package com.tdam2013.grupo12.broadcastReceiver;

import com.tdam2013.grupo12.MiWidget;
import com.tdam2013.grupo12.R;

import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.IBinder;
import android.widget.RemoteViews;

public class MyWidgetService extends Service {
	@Override
	public void onCreate() {
		super.onCreate();
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		buildUpdate();

		return super.onStartCommand(intent, flags, startId);
	}

	private void buildUpdate() {
		// Push update for this widget to the home screen
		AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
		ComponentName thisWidget = new ComponentName(this, MiWidget.class);
		RemoteViews updateViews = null;
		updateViews = new RemoteViews(this.getPackageName(), R.layout.miwidget);
		int[] ids = appWidgetManager.getAppWidgetIds(thisWidget);
		appWidgetManager
				.notifyAppWidgetViewDataChanged(ids, R.id.listaLlamadas);
		appWidgetManager.updateAppWidget(thisWidget, updateViews);
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

}
